<?php

namespace JLPay\Services\Openmerch\Register;

use JLPay\Services\BaseService;
use JLPay\Models\Openmerch\Register\IncomingQueryRequest;
use JLPay\Models\Openmerch\Register\IncomingQueryResponse;

/**
 * 进件查询服务
 */
class IncomingQueryService extends BaseService
{
    /**
     * 获取API URL
     *
     * @param string $requestClass 请求类名
     * @param string|null $apiPath 接口路径
     * @return string 完整的API URL
     */
    public function getApiUrl(string $requestClass, ?string $apiPath = null): string
    {
        $baseUrl = $this->config->getUrl();
        
        if ($apiPath) {
            return $baseUrl . $apiPath;
        }
        
        // 直接使用Request类中定义的完整API路径
        $apiUrl = constant($requestClass . '::API_URL');
        
        if (!$apiUrl) {
            // 如果没有定义API_URL，使用默认路径
            return $baseUrl . '/open/merch/access/incoming/query';
        }
        
        // 直接返回完整路径
        return $baseUrl . $apiUrl;
    }

    /**
     * 查询进件申请
     *
     * @param IncomingQueryRequest $request
     * @return IncomingQueryResponse
     */
    public function queryIncoming(IncomingQueryRequest $request): IncomingQueryResponse
    {
        return $this->post($request, IncomingQueryResponse::class);
    }
} 